﻿using DidaCode.Workflow.Logs;
using DidaCode.Workflow.Models;
using DidaCode.Workflow.Models.Parameters;
using DidaCode.Workflow.Models.Results;
using DidaCode.Workflow.NodeAttribute;
using DidaCode.Workflow.NodeBase;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DidaCode.Workflow.Nodes
{
    [NodeType(Node.HotelSearch)]
    public class HotelSearch : NodeBase<HotelSearchParameter, HotelSearchResult>
    {

        [AutoMap(Node.HotelSearch)]
        public string HotelName { get; set; }

        public HotelSearch(string switchConfig) : base(switchConfig)
        {

        }


        protected override async Task<NodeResult<HotelSearchResult>> ExecuteNodeAsync(ExecutionContext<HotelSearchParameter, HotelSearchResult> context)
        {
            // 模块HotelSearch的执行逻辑
            await Task.Delay(100); // 模拟异步操作

            HotelName = $"南山酒店+{Guid.NewGuid()}";

            StringBuilder sb = new StringBuilder(); 
            sb.AppendLine($"***************HotelSearch开始********************");

            sb.AppendLine($"[Thread: {Thread.CurrentThread.ManagedThreadId}]");
            sb.AppendLine("HotelSearch节点执行前的上下文信息:");
            sb.AppendLine($"{Node.HotelSearch}节点的HotelId{context.Input.HotelId}的HotelName:{HotelName}");
            sb.AppendLine("***************HotelSearch结束********************");
            Console.WriteLine(sb.ToString());
            ExecutionLogger.LogResult(Node.HotelSearch, new TypedResult(typeof(string), HotelName));

            context.Output.HotelName = HotelName;
            return NodeResult<HotelSearchResult>.SuccessNode(context.Output);
        }
    }


}
